unit uxSelectionFrame;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, StdCtrls,
uxCtrls;

//------------------------------------------------------------------------------
type

TSelectInfo = class(TFrame)
  LSelStart: TLabelEx;
  LSelLength: TLabelEx;
  LUnsignedValue: TLabelEx;
  LSignedValue: TLabelEx;
  LFloatValue: TLabelEx;
  LABEL_OFFSET: TLabelEx;
  LABEL_LENGTH: TLabelEx;
  LABEL_EMPTY: TLabelEx;
  LABEL_UNSIGNED: TLabelEx;
  LABEL_SIGNED: TLabelEx;
  LABEL_FLOAT: TLabelEx;
  LABEL_VALUE: TLabelEx;
private
  procedure ClearValue;
protected
  function CanResize(var NewWidth, NewHeight: Integer): Boolean; override;
  procedure PaintWindow(DC: HDC); override;
  procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
public
  procedure Clear;
  procedure SetSelection(Data: PByte; SelStart, SelLength: Integer);
end;

implementation

{$R *.dfm}

//------------------------------------------------------------------------------
function TSelectInfo.CanResize(var NewWidth, NewHeight: Integer): Boolean;
begin
  Result := NewHeight = Height;
end;
//------------------------------------------------------------------------------
procedure TSelectInfo.Clear;
begin
  LSelStart.Caption := '';
  LSelLength.Caption := '';
  ClearValue;
end;
//------------------------------------------------------------------------------
procedure TSelectInfo.ClearValue;
begin
  LUnsignedValue.Caption := '';
  LSignedValue.Caption := '';
  LFloatValue.Caption := '';
end;
//------------------------------------------------------------------------------
procedure TSelectInfo.SetSelection(Data: PByte; SelStart, SelLength: Integer);
begin
  LSelStart.Caption := IntToStr(SelStart);
  LSelLength.Caption := IntToStr(SelLength);
  case SelLength of
    1:
    begin
      LUnsignedValue.Caption := Format('%u', [Data^]);
      LSignedValue.Caption := Format('%d', [PShortInt(Data)^]);
      LFloatValue.Caption := '';
    end;
    2:
    begin
      LUnsignedValue.Caption := Format('%u', [PWord(Data)^]);
      LSignedValue.Caption := Format('%d', [PSmallInt(Data)^]);
      LFloatValue.Caption := '';
    end;
    4:
    begin
      LUnsignedValue.Caption := Format('%u', [PCardinal(Data)^]);
      LSignedValue.Caption := Format('%d', [PInteger(Data)^]);
      LFloatValue.Caption := FormatFloat('0.##', PSingle(Data)^);
    end;
    8:
    begin
      LUnsignedValue.Caption := Format('%u', [PUInt64(Data)^]);
      LSignedValue.Caption := Format('%d', [PInt64(Data)^]);
      LFloatValue.Caption := FormatFloat('0.##', PDouble(Data)^);
    end;
    else
      ClearValue;
  end;
end;
//------------------------------------------------------------------------------
procedure TSelectInfo.PaintWindow(DC: HDC);
var
  HBR: HBRUSH;
begin
  inherited;
  HBR := CreateSolidBrush(ColorToRGB(Color));
  FillRect(DC, ClientRect, HBR);
  DeleteObject(HBR);
end;
//------------------------------------------------------------------------------
procedure TSelectInfo.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  Message.Result := 1;
end;

end.
